<?php
/*
if(isset($_POST['upload']))
{
       $locFile = 'C:/Users/Diane/Desktop/Files/Invoice';
       //filesInDir('C:/Users/Diane/Desktop/Files/Invoice');
       //function filesInDir($locFile)
       {
               $dirs = scandir($locFile);
               foreach($dirs as $file)
               {
                       if (($file == '.')||($file == '..'))
                       {
                       }
                       elseif (is_dir($locFile.'/'.$file))
                       {
                               filesInDir($locFile.'|'.$file);
                       }
                       else
                       {
                               $location = $locFile.'/'.$file;
                               
                               //$file = $_FILES[$location]['tmp_name'];
                               $loop = 0;
                               $fp = @fopen($location,'r');
		while (!feof($fp))
		{
			$loop++;
			$line = fgets($fp,1024); //use 2048 if very long lines
			$field[$loop] = explode (',', $line);
			$dest=$_POST['location']; 
    
			mysql_connect("localhost","root","");
			mysql_select_db("gs3_tupperware");
			//24
			$file1 = $field[$loop][0];
			$file2 = $field[$loop][1];
			$file3 = $field[$loop][2];
			$file4 = $field[$loop][3];
			$file5 = $field[$loop][4];
			$file6 = $field[$loop][5];
			$file7 = $field[$loop][6];
			$file8 = $field[$loop][7];
			$file9 = $field[$loop][8];
			$file10= $field[$loop][9];
			$file11 = $field[$loop][10];
			$file12 = $field[$loop][11];
			$file13 = $field[$loop][12];
			$file14 = $field[$loop][13];
			$file15 = $field[$loop][14];
			$file16 = $field[$loop][15];
			$file17 = $field[$loop][16];
			$file18 = $field[$loop][17];
			$file19 = $field[$loop][18];
			$file20 = $field[$loop][19];
			$file21 = $field[$loop][20];
			$file22 = $field[$loop][21];
			$file23 = $field[$loop][22];
			$file24 = $field[$loop][23];
                        $file25 = $field[$loop][24];
                        $file26 = $field[$loop][25];
                        $file27 = $field[$loop][26];
                        $file28 = $field[$loop][27];
			
			//$file_location = $field[$loop][3];
			//$file_Name = $field[$loop][4];
			
			$file_uploaded_location = $dest.$file_Name;
			mysql_query("INSERT INTO tbdealer
			(branchCode,dealerCode,lastName,firstName,middleName,birthdate,appointmentDate,creditLimit,availableLimit,totalAmountDue,nextDueAmount,nextDueDate,invoiceNum,invoiceDate,Company,ProductMarket_CFT,ProductMarket_NCFT,Segment_Beauty,Segment_Fashion,Segment_Home,category_a,category_b,productline_a,productline_b,brand_a,brand_b,subBrand_a,subBrand_b,is_active)
			VALUES('$file1','$file2','$file3','$file4','$file5','$file6','$file7','$file8','$file9','$file10',
			'$file11','$file12','$file13','$file14','$file15','$file16','$file17','$file18','$file19','$file20','$file21','$file22','$file23','$file24',
                        '$file25','$file26','$file27','$file28','1')");
			$src=$file_location; 
			$srcfile=$file_location.$file_Name; 
			//$list= read_dir($src); 
			//foreach($list as $key => $val) 
			//{ 	
			    //copy file to new folder 
			    //copy("$src$val","$dest$val");
			    //unlink("$src$val");
                            //$dir = "C:\wamp\www\GS3\Tupperware\gs3_tupperware\images\invoice";
                            
			//} 	
			//$fp++;
			//echo "<meta HTTP-EQUIV='REFRESH' content='0; url=documents.php'>";
		}
		echo '<script>alert("Files was successfully uploaded")</script>';
			fclose($fp);
			
                       }
               }
       }
}*/
?>
<!--form action="" method="POST" enctype="multipart/form-data">
       <input type="submit" name="upload">
</form-->
<?php
/*
// Get array of all source files
$locFile = 'C:/Users/Diane/Desktop/Files/Invoice/';
    $files = scandir($locFile);
    // Identify directories
    $source = $locFile;
    $dest = "C:/wamp/www/Files/Invoice/";
    $destination = $dest;
    // Cycle through all source files
    foreach ($files as $file) {
      if (in_array($file, array(".",".."))) continue;
      // If we copied this successfully, mark it for deletion
      if (copy($source.$file, $destination.$file)) {
        $delete[] = $source.$file;
      }
    }
    // Delete all successfully-copied files
    foreach ($delete as $file) {
      unlink($file);
    }
*/
mysql_connect("localhost","root","");
mysql_select_db("gs3_tupperware");

$query = mysql_query("SELECT * FROM tbdealer WHERE dealerCode='3223422'");
$ctr = 0;
while($row = mysql_fetch_array($query))
{
       //echo "<center>".$row['pointsEarned']."<br><br><br></center>";
       $getPoints = $row['pointsEarned'];

//First Explode

$headerCount=0;
 /*
for($a=0;$a<=$firstCount;$a++)
{
       $second = explode("-:-",$first[$a]);
       $secondCount = count($second);
       //echo $second[0]."<br>".$second[1]."<br>";
       //echo $second[0]."<br>";
for($a1=0;$a1<=$secondCount;$a1++)
{
       $third = explode("/:/",$second[$a1]);
       $thirdCount = count($third);
       for($b=0;$b<=$thirdCount;$b++)
       {
              //echo $third[$b]."<br>";
              //echo $headerCount++;
              $fourth = explode("-|-",$third[$b]);
              $fourthCount = count($fourth);
              for($c=0;$c<=$fourthCount;$c++)
              {
                     echo $fourth[$c]."\n";
              }
       }
              //$second1 = explode("-|-",$second[0]);
              //echo $second1[0]."<br>".$second1[1]."<br>";
}
echo "<br>";
      
       $third = explode("-:-",$first[$a]);
       //echo $third[0]."<br>".$third[1]."<br>";
       echo $third[0]."<br>";
              $third1 = explode("/:/",$third[1]);
              //echo $third1[0]."<br>".$third1[1]."<br>";
              
       $fourth = explode("-|-",$third1[0]);
       echo $fourth[0]."<br>".$fourth[1]."<br>";
       $fourth = explode("-|-",$third1[1]);
       echo $fourth[0]."<br>".$fourth[1]."<br>";
       
}*/
//echo $firstCount;
/*
$first = explode("[-]",$getPoints);
$firstCount = count($first);
for($a=0;$a<=$firstCount;$a++)
{
       //echo $first[$a]."<br>";
       echo "<br>";
       //echo $first[$a]."\n";
       
       //echo $second[0]."<br>".$second[1]."<br>";
       
       $second = explode("-:-",$first[$a]);
       $secondCount = count($second);
       for($b=0;$b<=$secondCount;$b++)
       {
              //echo $second[$b]."\n";
              
              $third = explode("-|-",$second[$b]);
              $thirdCount = count($third);
              for($c=0;$c<=$thirdCount;$c++)
              {
                    // echo $third[$c]."\n";
                     
                     $fourth = explode("/:/",$third[$c]);
                     $fourthCount = count($fourth);
                     for($d=0;$d<=$fourthCount;$d++)
                     {
                            echo $fourth[$d]."\n";
                     }
                     
              }
              
       }

}
echo "<br/><br/>";
}*/

    $first = explode("[-]",$getPoints);
    for($a=0;$a<count($first);$a++){
        //echo "<br />";
        $second = explode("-:-",$first[$a]);
        for($b=0;$b<count($second);$b++){
            //echo "<br />";
            $third = explode("/:/",$second[$b]);
            for($c=0;$c<count($third);$c++){
                $fourth = explode("-|-",$third[$c]);
                for($d=0;$d<count($fourth);$d++){
                    //echo $fourth[0]."  ".$fourth[1]." ";
                    $ctr++;
                    if($ctr==1){
                        //echo $fourth[0]." //head";
                    }else{
                        if($fourth[0]=="Company"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $companyPoints+=$fourth[1];
                        }elseif($fourth[0]=="Company1"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $company1Points+=$fourth[1];
                        }elseif($fourth[0]=="Company2"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $company2Points+=$fourth[1];
                        }elseif($fourth[0]=="CFT"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $cftPoints+=$fourth[1];
                        }elseif($fourth[0]=="NCFT"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $ncftPoints+=$fourth[1];
                        }elseif($fourth[0]=="Beauty"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $beautyPoints+=$fourth[1];
                        }elseif($fourth[0]=="Fashion"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $fashionPoints+=$fourth[1];
                        }elseif($fourth[0]=="Home"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $homePoints+=$fourth[1];
                        }elseif($fourth[0]=="Baby"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $babyPoints+=$fourth[1];
                        }elseif($fourth[0]=="Cat A"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $catAPoints+=$fourth[1];
                        }elseif($fourth[0]=="Cat B"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $catBPoints+=$fourth[1];
                        }elseif($fourth[0]=="Prod A"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $prodAPoints+=$fourth[1];
                        }elseif($fourth[0]=="Prod B"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $prodBPoints+=$fourth[1];
                        }elseif($fourth[0]=="Brand A"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $brandAPoints+=$fourth[1];
                        }elseif($fourth[0]=="Brand B"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $brandBPoints+=$fourth[1];
                        }elseif($fourth[0]=="Sub A"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $subAPoints+=$fourth[1];
                        }elseif($fourth[0]=="Sub B"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $subBPoints+=$fourth[1];
                        }elseif($fourth[0]=="Form A"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $formAPoints+=$fourth[1];
                        }elseif($fourth[0]=="Form B"){
                            //echo $fourth[0]."(sub head)";
                            //echo $fourth[1]."(points)";
                            $formBPoints+=$fourth[1];
                        }
                    }
                    //echo "<br />";
                    break;
                }
            }
        }
        $ctr = 0;
    }
    //echo "<br /><br />";
    
}
//Second Explode
echo "Kopmanya:<br />";
echo "Total points for Company = ".$companyPoints."<br />";
echo "Total points for Company1 = ".$company1Points."<br />";
echo "Total points for Company2 = ".$company2Points."<br />";
echo "Product Market:<br />";
echo "Total points for CFT = ".$cftPoints."<br />";
echo "Total points for NCFT = ".$ncftPoints."<br />";
echo "Segment:<br />";
echo "Total points for Beauty = ".$beautyPoints."<br />";
echo "Total points for Fashion = ".$fashionPoints."<br />";
echo "Total points for Home = ".$homePoints."<br />";
echo "Total points for Baby = ".$babyPoints."<br />";
echo "Category:<br />";
echo "Total points for Cat A = ".$catAPoints."<br />";
echo "Total points for Cat B = ".$catBPoints."<br />";
echo "Product Line:<br />";
echo "Total points for Prod A = ".$prodAPoints."<br />";
echo "Total points for Prod B = ".$prodBPoints."<br />";
echo "Brand:<br />";
echo "Total points for Brand A = ".$brandAPoints."<br />";
echo "Total points for Brand B = ".$brandBPoints."<br />";
echo "Sub Brand:<br />";
echo "Total points for Sub A = ".$subAPoints."<br />";
echo "Total points for Sub B = ".$subBPoints."<br />";
echo "Form:<br />";
echo "Total points for Form A = ".$formAPoints."<br />";
echo "Total points for Form B = ".$formBPoints."<br />";







